package top.arwtec.mcm.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import top.arwtec.mcm.enums.UserEnum;
import top.arwtec.mcm.service.UserInfoService;

/**
 * @author liyin
 */
@Service
@RequiredArgsConstructor
public class UserDetailServiceImpl implements ReactiveUserDetailsService {
    private final UserInfoService userInfoService;

    @Override
    public Mono<UserDetails> findByUsername(String username) {
        UserDetails user = userInfoService.getUserInfo(username);
        if (user == null) {
            throw new UsernameNotFoundException(UserEnum.USER_NOT_EXIST.getMsg());
        }
        return Mono.just(user);
    }
}
